finp$="picture.png"

fout$=finp$+".bin"
' converts a 256x192 2c picture into a 'pmode4:screen1,1' binary file
setdisplay(256,192,32,1):paper(8^8-1):ink(0):pen(0):cls
loadimage(finp$,1):pasteicon(0,0,1)
open fout$ for output as #1
dim clust[8,8]:a$="00,06,08,14,02,12,04,10,08,14,00,06,04,10,02,12"
for y2=0 to 3:for x2=0 to 3:lc=(y2*4)+x2:clust[x2,y2]=val(mid$(a$,(lc*3)+1,2)):next:next
for y=0 to 191
  for x1=0 to 31
    btv=0:btt=0
    for x2=7 to 0 step -1
      x=x1*8+(7-x2)
      btv=btv*2
      u=point(x,y)
      b=u mod 256: u=int(u/256)
      g=u mod 256: u=int(u/256)
      r=u mod 256: u=int(u/256)
      w=int(((b*11)+(r*30)+(g*59))/100)
      patgf=(((clust[x mod 4,y mod 4]+1)*255)/16)
      btt=0:ink(0x000000):if w>patgf then:btt=1:ink(0xFFFFFF):end if
      dot(x,y)
      btv=btv+btt
      next
    writebyte(1,btv)
    next:next
foutp$=finp$+".bmp":grab(1,0,0,256,192):saveimage(foutp$,1)
shell("convert "+finp$+".bmp "+finp$+".png && rm "+finp$+".bmp")
close #1

